<template>
  <div class="con">
    <div class="left">
      <div class="echartsLeft" id="labour8EchartsLeft"></div>
    </div>
    <div class="right">
      <div class="echartsRight" id="labour8EchartsRight"></div>
    </div>
  </div>
</template>
    
    <script>
export default {
  name: "labourArea8",
  data() {
    return {
      numberAll: 268,
      optionLeft: {
        title: {
          text: "年龄分布",
          textStyle: {
            color: "#ccc",
            fontWeight: "normal",
            fontSize: "16px",
            fontFamily: "Microsoft YaHei",
          },
        },
        tooltip: {
          trigger: "axis",
          backgroundColor: "rgba(255,255,255,0.8)",
          extraCssText: "box-shadow: 0 0 8px rgba(0, 0, 0, 0.3)",
          textStyle: {
            color: "#6a717b",
          },
        },
        grid: {
          top: "15%",
          left: "3%",
          right: "11%",
          bottom: "2.5%",
          containLabel: true,
        },
        yAxis: [
          {
            type: "category",
            data: ["18-35", "36-45", "46-55", "55以上"],
            inverse: true,
            axisTick: {
              alignWithLabel: true,
            },
            axisLabel: {
              margin: 10,
              textStyle: {
                fontSize: 16,
                color: "#7693b9",
              },
            },
            axisLine: {
              lineStyle: {
                color: "#2548ac",
              },
            },
          },
        ],
        xAxis: [
          {
            type: "value",
            show: false,
            axisLine: {
              lineStyle: {
                color: "#192469",
              },
            },
            splitLine: {
              lineStyle: {
                color: "#17367c",
              },
            },
          },
        ],

        series: [
          {
            name: "Top 10",
            type: "bar",
            barWidth: 8,
            data: [88, 74, 73, 33],
            label: {
              normal: {
                show: true,
                position: "right",
                textStyle: {
                  color: "#3f9bf7", //color of value
                  fontSize: 12,
                },
                formatter: (params) => {
                  var percent =
                    Number((params.data / this.numberAll) * 100).toFixed(0) +
                    "%";
                  return percent;
                },
              },
            },

            itemStyle: {
              normal: {
                color: {
                  type: "linear",
                  x: 0, //右
                  y: 0, //下
                  x2: 1, //左
                  y2: 0, //上
                  colorStops: [
                    {
                      offset: 0,
                      color: "#5b247a", // 0% 处的颜色
                    },
                    // {
                    //   offset: 0.5,
                    //   color: "#5b247a", // 70% 处的颜色
                    // },
                    {
                      offset: 1,
                      color: "#1bcedf", // 100% 处的颜色linear-gradient(90deg,#5b247a,#1bcedf)
                    },
                  ],
                },

                barBorderRadius: [0, 15, 15, 0],

                shadowColor: "rgba(0,0,0,0.1)",

                shadowBlur: 3,

                shadowOffsetY: 3,
              },
            },
          },
        ],
      },
      optionRight: {
        title: {
          text: "性别分布",
          textStyle: {
            color: "#ccc",
            fontWeight: "normal",
            fontSize: "16px",
            fontFamily: "Microsoft YaHei",
          },
        },
        tooltip: {
          trigger: "axis",
          backgroundColor: "rgba(255,255,255,0.8)",
          extraCssText: "box-shadow: 0 0 8px rgba(0, 0, 0, 0.3)",
          textStyle: {
            color: "#6a717b",
          },
        },
        grid: {
          top: "15%",
          left: "3%",
          right: "11%",
          bottom: "2.5%",
          containLabel: true,
        },
        yAxis: [
          {
            type: "category",
            data: ["男", "女"],
            inverse: true,
            axisTick: {
              alignWithLabel: true,
            },
            axisLabel: {
              margin: 10,
              textStyle: {
                fontSize: 16,
                color: "#7693b9",
              },
            },
            axisLine: {
              lineStyle: {
                color: "#2548ac",
              },
            },
          },
        ],
        xAxis: [
          {
            type: "value",
            show: false,
            axisLine: {
              lineStyle: {
                color: "#192469",
              },
            },
            splitLine: {
              lineStyle: {
                color: "#17367c",
              },
            },
          },
        ],

        series: [
          {
            name: "性别",
            type: "bar",
            barWidth: 8,
            data: [161, 107],
            label: {
              normal: {
                show: true,
                position: "right",
                textStyle: {
                  color: "#3f9bf7", //color of value
                  fontSize: 12,
                },
                formatter: (params) => {
                  var percent =
                    Number((params.data / this.numberAll) * 100).toFixed(0) +
                    "%";
                  return percent;
                },
              },
            },

            itemStyle: {
              normal: {
                color: {
                  type: "linear",
                  x: 0, //右
                  y: 0, //下
                  x2: 1, //左
                  y2: 0, //上
                  colorStops: [
                    {
                      offset: 0,
                      color: "#38fff2", // 0% 处的颜色
                    },
                    {
                      offset: 0.7,
                      color: "#2378f7", // 70% 处的颜色
                    },
                    {
                      offset: 1,
                      color: "#3f9bf7", // 100% 处的颜色
                    },
                  ],
                },

                barBorderRadius: [0, 15, 15, 0],

                shadowColor: "rgba(0,0,0,0.1)",

                shadowBlur: 3,

                shadowOffsetY: 3,
              },
            },
          },
        ],
      },
    };
  },
  methods: {},
  mounted() {
    const myChartsLeft = this.$echarts.init(
      document.getElementById("labour8EchartsLeft")
    );
    myChartsLeft.setOption(this.optionLeft);
    const myChartsRight = this.$echarts.init(
      document.getElementById("labour8EchartsRight")
    );
    myChartsRight.setOption(this.optionRight);
  },
};
</script>
    
<style lang="scss" scoped>
.con {
  display: flex;
  .left {
    width: 215px;
    height: 235px;
    .echartsLeft {
      width: 215px;
      height: 235px;
    }
  }
  .right {
    .echartsRight{
      width: 235px;
      height: 235px;
    }
  }
}
</style>